package com.xiaoxi.observermode.observer;

import com.xiaoxi.observermode.generator.NumberGenerator;

import java.awt.*;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.observermode.observer
 * @ClassName GraphCanvasObserver
 * @Description TODO
 * @Date 2023/3/27 19:57
 * @Version 1.0
 */
public class GraphCanvasObserver extends Canvas implements Observer {

    private int number;

    @Override
    public void update(NumberGenerator numberGenerator) {
        number = numberGenerator.getNumber();
        repaint();
    }

    @Override
    public void paint(Graphics g) {
        g.setColor(Color.white);
        g.fillArc(0, 0, getWidth(), getHeight(), 0, 360);
        g.setColor(Color.red);
        g.fillArc(0, 0, getWidth(), getHeight(), 0, number);
    }
}
